package com.chagee.store.operation.server.event.service;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chagee.store.operation.server.entity.AppealReviewerConfigurationDO;
import com.chagee.store.operation.server.entity.WorkOrderDO;
import com.chagee.store.operation.server.event.dao.AppealReviewerConfigurationMapper;
import com.chagee.store.operation.server.model.param.AppealReviewerListParam;
import com.chagee.store.operation.server.model.param.UpdateAppealReviewerParam;
import com.chagee.store.operation.server.service.IAppealReviewerConfigurationService;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhiqin.yuan
 * @since 2024-06-27
 */
@Service
@RequiredArgsConstructor
public class AppealReviewerConfigurationBaseService extends ServiceImpl<AppealReviewerConfigurationMapper, AppealReviewerConfigurationDO> implements IAppealReviewerConfigurationService {


	public AppealReviewerConfigurationDO queryByreveiwerAndCompany(String reveiwerId, String companyId) {
		return lambdaQuery()
			.eq(AppealReviewerConfigurationDO::getReveiwerId, reveiwerId)
			.eq(AppealReviewerConfigurationDO::getCompanyId, companyId)
			.eq(AppealReviewerConfigurationDO::getDeleteFlag,0)
			.one();
	}

	public List<AppealReviewerConfigurationDO> queryByCompany(String companyId) {
		return lambdaQuery()
			.eq(AppealReviewerConfigurationDO::getCompanyId, companyId)
			.eq(AppealReviewerConfigurationDO::getDeleteFlag,0)
			.list();
	}

	public List<AppealReviewerConfigurationDO> queryByReveiwerId(String reveiwerId) {
		return lambdaQuery()
			.eq(AppealReviewerConfigurationDO::getReveiwerId, reveiwerId)
			.eq(AppealReviewerConfigurationDO::getDeleteFlag, NumberUtils.INTEGER_ZERO)
			.list();
	}

	public List<AppealReviewerConfigurationDO> queryByRegion(String region) {
		return lambdaQuery()
			.like(AppealReviewerConfigurationDO::getCityRegion, region)
			.eq(AppealReviewerConfigurationDO::getDeleteFlag, NumberUtils.INTEGER_ZERO)
			.list();
	}

	/**
	 * 分页查询审核人信息
	 *
	 * @param queryParameter param
	 * @param page           page
	 * @return page
	 */
	public Page<AppealReviewerConfigurationDO> pageQueryAppealReviewer(AppealReviewerListParam queryParameter, Page<AppealReviewerConfigurationDO> page) {
		return baseMapper.pageQueryAppealReviewer(page, queryParameter);

	}


	public Boolean update(UpdateAppealReviewerParam param, AppealReviewerConfigurationDO configurationDO){
		return this.update(
			lambdaUpdate().eq(AppealReviewerConfigurationDO::getId, configurationDO.getId())
				.set(AppealReviewerConfigurationDO::getReveiwerId, param.getReveiwerId())
				.set(AppealReviewerConfigurationDO::getReveiwerName, param.getReveiwerName())
				.set(AppealReviewerConfigurationDO::getCompanyId, param.getCompanyId())
				.set(AppealReviewerConfigurationDO::getCompanyName, param.getCompanyName())
				.set(CollectionUtil.isNotEmpty(param.getCityCode()), AppealReviewerConfigurationDO::getCityRegion, JSONUtil.toJsonStr(param.getCityCode()))
				.getWrapper());
	}
}
